#!/bin/bash
#THIS SCRIPT WILL INSTALL AND CONFIGURE MODEM HANDELING PROTOCOLS ON
#CARBLOGGER WHERE A US ROBTICS v.92 HAS BEEN CONNECTED TO /dev/ttyS0

config_wvdial()
	{
	
	echo "[Dialer Defaults]" > /etc/wvdial.conf
	echo "Init1 = ATZ X3" >> /etc/wvdial.conf
	echo "Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0" >> /etc/wvdial.conf
	echo "Baud = 115200" >> /etc/wvdial.conf
	echo "New PPPD = yes" >> /etc/wvdial.conf
	echo "Modem = /dev/ttyS0" >> /etc/wvdial.conf
	echo "Abort on No Dialtone = off" >> /etc/wvdial.conf 
	echo "ISDN = 0" >> /etc/wvdial.conf 

########Dial Prefix = 9?################
	echo "Do you need to dial a nine to get out?(Y/N)"
	read d9
	if [[ $d9 == "Y" || $d9 == "y" || $d9 == "yes" ]]; then
	    { 
		phone_number="9,,"       
	    }
	fi
	clear
	echo "Do you need to dial a long distance number?(Y/N)"
	read lng_dst
	if [[ $lng_dst == "Y" || $lng_dst == "y" || $lng_dst == "yes" ]]; then
	    { 
		clear
		echo "Enter the area code"
		read ac
		phone_number="$phone_number,$ac"
       
	    }
	fi
	clear
	echo "Enter your telephone number."
	read tel_nmbr
	if [[ $lng_dst == "Y" || $lng_dst == "y" || $lng_dst == "yes" ]]; then
	    { 
		clear
		echo "Enter the area code"
		read ac
		phone_number="$phone_number,1,$ac"
       
	    }
	fi
	clear
	 
Phone = 9,,239-1010
Password = nada
Username = anonymous


	}
clear
if [[ `id -u` -ne 0 ]]; then
{
	echo "'$0' Needs to be run as root."
	echo "Please run from the root terminal"
	exit;
}
else
{
	clear
	if !(nslookup google.com); then
		{
			echo "Sorry this script needs network to continue. Exiting";
			exit;
		}
	fi
}
fi
#######################################
#		INSTALL WVDIAL -- MJV #			
#######################################
if [-z `which wvdial`]; then
	echo "Need to install modem handeler...installing"
	sleep 5
	
	if (apt-get install wvdial); then
			{
				echo "Remote wvdial installed"
			}
		else
			{
				echo "Failed to install wvdial"
				exit					
			}
	fi
fi
wait $!


